package top.aiprogram.aop;

import jdk.nashorn.internal.scripts.JO;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class UserAspect {

    @Pointcut(value = "execution(* top.aiprogram.service.*.*(..))")
    public void pointCut() {
    }

    @Before(value = "pointCut()")
    public void doBefore(JoinPoint joinPoint) {
        String name = joinPoint.getSignature().getName();
        Object[] obj = joinPoint.getArgs();
        System.out.println(name + "     " + obj.toString());

    }

    @After(value = "pointCut()")
    public void doAfter(JoinPoint joinPoint) {


    }

    @AfterReturning(value = "execution(* top.aiprogram.service.*.character(..))", returning = "result")
    public void afterReturning(JoinPoint joinPoint, Object result) {
        System.out.println(result);
    }

    @Around(value = "pointCut()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) {
        try {
            proceedingJoinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

    @AfterThrowing(value = "pointCut()")
    public void afterThrowing(JoinPoint joinPoint) {

    }


}
